  
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">交易记录</a>
    <a><cite>明细记录</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-userfront-formlist">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-block">
            <input type="text" name="account" placeholder="请输入" autocomplete="off" class="layui-input">
          </div>
        </div>
        <!-- <div class="layui-inline">
          <label class="layui-form-label">商品名称</label>
          <div class="layui-input-block">
            <input type="text" name="username" placeholder="请输入" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">商品价格</label>
          <div class="layui-input-block">
            <input type="text" name="email" placeholder="请输入" autocomplete="off" class="layui-input">
          </div>
        </div> -->
        <div class="layui-inline">
          <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
          </button>
        </div>
      </div>
    </div>
    
    <div class="layui-card-body">
      <div style="padding-bottom: 10px;">
        <!-- <button class="layui-btn layuiadmin-btn-useradmin" data-type="batchdel">删除</button> -->
        <!-- <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button> -->
      </div>
      
      <table id="LAY-record-manage" lay-filter="LAY-record-manage"></table>

      <script type="text/html" id="imgTpl"> 
        <img style="display: inline-block; width: 50%; height: 100%;" src= "{{ d.mainPicture }}"/>
      </script> 
      <!-- <script type="text/html" id="table-useradmin-webuser"> -->
        <!-- <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a> -->
        <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a> -->
      <!-- </script> -->
    </div>
  </div>
</div>

<script type="text/javascript">
  function createTime(v){
    var date = new Date(v);
      var y = date.getFullYear();
      var m = date.getMonth()+1;
      m = m<10?'0'+m:m;
      var d = date.getDate();
      d = d<10?("0"+d):d;
      var h = date.getHours();
      h = h<10?("0"+h):h;
      var M = date.getMinutes();
      M = M<10?("0"+M):M;
      var str = y+"-"+m+"-"+d+" "+h+":"+M;
      return str;
  }
</script>
<script>
layui.use('record', layui.factory('record')).use(['admin', 'record', 'table'], function(){
  var $ = layui.$
  ,admin = layui.admin
  ,view = layui.view
  ,table = layui.table
  ,form = layui.form
  ,setter = layui.setter;
  
  form.render(null, 'layadmin-userfront-formlist');
  
  //监听搜索
  form.on('submit(LAY-user-front-search)', function(data){
    var field = data.field;
    
    //用户管理
    table.render({
      elem: '#LAY-record-manage'
      // ,url: './json/useradmin/webuser.js' //模拟接口
      ,url: setter.myurl + 'admin/tran/listBy' //模拟接口
      ,cols: [[
        {type: 'checkbox', fixed: 'left'}
        ,{field: 'ttype', width: 100, title: '交易类型'}
        ,{field: 'numb', title: '交易数量'}
        ,{field: 'recordType', title: '记录类型', width: 100}
        ,{field: 'inoutType', title: '进出账类型'}
        ,{field: 'account', title: '用户名'}
        ,{field: 'remark', title: '备注'}
        ,{field: 'createDate', title: '创建时间', sort: true, templet :function (row){return createTime(row.createDate);}}
        // ,{title: '操作', width: 150, align:'center', fixed: 'right', toolbar: '#table-useradmin-webuser'}
      ]]
      ,where: field
      ,method: 'POST'
      ,page: true
      ,limit: 10
      ,limits: [10,20,30,40,50,100,1000,5000,200000]
      ,height: 'full-320'
      ,text: '对不起，加载出现异常！'
      ,contentType: 'application/json'
      ,done:function(res, curr, count){  //res 接口返回的信息
        $("[data-field = 'numb']").children().each(function(){
          //分单位转元单位
          if($(this).text() !=  '交易数量'){
            $(this).text(($(this).text()/100).toFixed(2));
          }
        })
        $("[data-field = 'ttype']").children().each(function(){
          // 交易类型，1：PS积分挖矿收益，2：PZSH任务挖矿收益，3：PS消费奖励PZSH，" +
          //     "4：ps转账，5：pzsh转账，6：RD转ps，7：ps转PZSH, 8: 赠送消费积分，" +
          //     "9：消费积分转账, 10：转账手续费, 11：购买升级套餐, 12：购买商城商品，" +
          //     "13:RD兑换手续费, 14:发放ps, 15:商城消费奖励PS积分, 16:商城订单取消返回PS, 17:商城订单取消返回消费积分，18：下级购买商城订单奖励直推上级PS
          if($(this).text() == '1'){
            $(this).text("PS积分挖矿收益");
          }else if($(this).text() == '2'){
            $(this).text("PZSH任务挖矿收益");
          }else if($(this).text() == '3'){
            $(this).text("PS消费奖励PZSH");
          }else if($(this).text() == '4'){
            $(this).text("ps转账");
          }else if($(this).text() == '5'){
            $(this).text("pzsh转账");
          }else if($(this).text() == '6'){
            $(this).text("RD转ps");
          }else if($(this).text() == '7'){
            $(this).text("ps转PZSH");
          }else if($(this).text() == '8'){
            $(this).text("赠送消费积分");
          }else if($(this).text() == '9'){
            $(this).text("消费积分转账");
          }else if($(this).text() == '10'){
            $(this).text("转账手续费");
          }else if($(this).text() == '11'){
            $(this).text("购买升级套餐");
          }else if($(this).text() == '12'){
            $(this).text("购买商城商品");
          }else if($(this).text() == '13'){
            $(this).text("RD兑换手续费");
          }else if($(this).text() == '14'){
            $(this).text("发放ps");
          }else if($(this).text() == '15'){
            $(this).text("商城消费奖励PS积分");
          }else if($(this).text() == '16'){
            $(this).text("商城订单取消返回PS");
          }else if($(this).text() == '17'){
            $(this).text("商城订单取消返回消费积分");
          }else if($(this).text() == '18'){
            $(this).text("下级购买商城订单奖励直推上级PS");
          }
        })

        $("[data-field = 'recordType']").children().each(function(){
          //记录类型：1：转换记录，2：提现记录，3：充值记录
          if($(this).text() == '1'){
            $(this).text("转换记录");
          }else if($(this).text() == '2'){
            $(this).text("提现记录");
          }else if($(this).text() == '3'){
            $(this).text("充值记录");
          }else if($(this).text() == '0'){
            $(this).text("其他");
          }
        })

        $("[data-field = 'inoutType']").children().each(function(){
          //进出账类型：0：出账，1：进账
          if($(this).text() == '0'){
            $(this).text("出账");
          }else if($(this).text() == '1'){
            $(this).text("进账");
          }
        })
      }
    });
  });

  //事件
  var active = {
    batchdel: function(){
      var checkStatus = table.checkStatus('LAY-grade-manage')
      ,checkData = checkStatus.data; //得到选中的数据

      if(checkData.length === 0){
        return layer.msg('请选择数据');
      }
      
      layer.prompt({
        formType: 1
        ,title: '敏感操作，请验证口令'
      }, function(value, index){
        layer.close(index);
        
        layer.confirm('确定删除吗？', function(index) {
          
          //执行 Ajax 后重载
          /*
          admin.req({
            url: 'xxx'
            //,……
          });
          */
          table.reload('LAY-grade-manage');
          layer.msg('已删除');
        });
      });
    }
    ,add: function(){
      admin.popup({
        title: '添加复消商品'
        ,area: ['1300px', '850px']
        ,id: 'LAY-popup-user-add'
        ,shade: false 
        ,success: function(layero, index){
          view(this.id).render('grade/userform').done(function(){
            form.render(null, 'layuiadmin-form-useradmin');
            
            //监听提交
            form.on('submit(LAY-user-front-submit)', function(data){
              var field = data.field; //获取提交的字段

              //提交 Ajax 成功后，关闭当前弹层并重载表格
              //$.ajax({});
              $.ajax({
                url: setter.myurl + "admin/grade/add",
                data: JSON.stringify(field),
                type: "POST",
                dataType: "json",
                contentType: "application/json",
                success: function(data){
                  if(data.code == 0){
                    console.log("复消商品添加成功");
                    layui.msg("复消商品添加成功");
                    layui.table.reload('LAY-grade-manage'); //重载表格
                    layer.close(index); //执行关闭 
                  }else{
                    console.log("复消商品添加失败");
                    layui.msg("复消商品添加失败");
                  }
                  
                }
              });
              // layui.table.reload('LAY-grade-manage'); //重载表格
              // layer.close(index); //执行关闭 
            });
          });
        }
      });
    }
  };
  
  $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});
</script>